home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / examples / programs / dp_create.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-08  |  13.1 KB  |  386 lines

  1. #ifndef lint
  2. static char SccsId[]= "@(#)dp_create.c    V1.21    3/22/95";
  3. #endif
  4.  
  5. /*
  6. |    file name dp_create.c
  7. |===================================================================
  8. |
  9. |       This program shows how to create drawports based on a layout
  10. |       file created in DV-Draw.
  11. |
  12. |    This program loads a layout file, extracts named rectangles
  13. |       and uses their world coordinates to determine where to
  14. |    create drawports. This program assumes that the "areas" were
  15. |    defined relative to the whole world. That is, in DV-Draw,
  16. |       the user "Zoomed Out" until the whole world was visible,
  17. |       this "world" maps to the "screen" and the "areas" map to the
  18. |       "vvp" to use when creating the drawport. The whole view will
  19. |    be "stretched" to fit into the drawports.
  20. |
  21. |    The program displays the views and waits for the user to
  22. |       quit by selecting a <q|Q> key, the right mouse button, or
  23. |       an object named "quit".
  24. |
  25. |===================================================================
  26. */
  27. #include <windows.h>
  28.  
  29.  
  30. /* DV-Tools header files */
  31. #include "std.h"            /* <stdio.h> etc., scalar & macro definitions */
  32. #include "dvstd.h"          /* public types & constants */
  33. #include "dvtools.h"        /* constants used by T routines */
  34. #include "dvGR.h"           /* constants used by window mgt & GR routines */
  35. #include "VOstd.h"          /* constants used by VO & VOob routines */
  36. #include "Tfundecl.h"       /* T routines (screens, drawports & views) */
  37. #include "VOfundecl.h"      /* VO routines (objects) */
  38. #include "VUerfundecl.h"    /* VUer routines (event handling routines) */
  39.  
  40.  
  41. /* Constants */
  42. #define  DVPATH            (char *)NULL
  43. #define  DISPFORMS_STB     (char *)NULL
  44. #define  DVDEVICE          (char *)NULL
  45. #define  DVCOLORTABLE      (char *)NULL
  46. #define  SCREEN_VIEWPORT   (RECTANGLE *)NULL
  47. #define  DRAWING_VIEWPORT  (RECTANGLE *)NULL
  48.  
  49. #define NUM_DRAWPORTS 2
  50.  
  51. /* Define & initialize names of screen, view files, layout file, and area */
  52. LOCAL char *device_name = DVDEVICE;
  53. LOCAL char *view_name[NUM_DRAWPORTS] =
  54. {
  55.   "play.v",
  56.   "message.v",
  57. };
  58. LOCAL char *layout_name = "dp.lay";
  59. LOCAL char *area_name[NUM_DRAWPORTS] =
  60. {
  61.   "main.area",
  62.   "message.area",
  63. };
  64.  
  65. /* Whole world rectangle, (-16384, -16384) to (16383, 16383)*/
  66. LOCAL RECTANGLE whole_world =
  67. {XMIN, YMIN, XMAX, YMAX};
  68.  
  69.  
  70. /*
  71.  *   MAIN PROGRAM
  72.  */
  73. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  74.                      LPSTR lpCmdLine,  int nCmdShow  )
  75. {
  76.   INT argc = 0;
  77.   CHAR **argv;
  78.  
  79.   /*  program arguments
  80.    *    argv[1] - display device (default is DVDEVICE)
  81.    */
  82.  
  83.   /* Define display variables */
  84.   OBJECT screen;                     /* display device, the window */
  85.   DRAWPORT drawport[NUM_DRAWPORTS];  /* how & where to display each picture */
  86.   VIEW layout_view,                  /* representation of the view with
  87.                     rectangular layout areas */
  88.   view[NUM_DRAWPORTS];               /* picture representation of 
  89.                     each view file */
  90.  
  91.   /* Control loop variables */
  92.   OBJECT location;       /* cursor position details */
  93.   OBJECT layout_dr;      /* graphical portion of the layout view */
  94.   int i;                 /* an index variable */
  95.   int event_status;      /* how the event handler has used the 
  96.                 location event */
  97.  
  98.   /* Layout rectangle variables */
  99.   RECTANGLE box,                /* world coordinate drawport area */
  100.             svp_delta,          /* allowance for line thickness */
  101.             vvp;                /* virtual coordinate drawport area */
  102.   char *obj_name;               /* name of object at location */
  103.  
  104.   /* Other variables */
  105.   int Quit = NO;                /* flag to quit program */
  106.  
  107.  
  108.  
  109.  
  110.   /*--------------------
  111.    *  Initialization
  112.    *
  113.    *   TInit:  perform the initialization of DV-Tools
  114.    *           TInit reads your configuration file and any
  115.    *           environment variables or logical names set.
  116.    */
  117.   make_argv(&argc,&argv,GetCommandLine());
  118.   TInit (DVPATH, DISPFORMS_STB);
  119.  
  120.   /*
  121.    *   TscOpenSet: open a device as a screen object using
  122.    *               specified attributes
  123.    *   TscErase:   erase the entire screen in the default
  124.    *               background color
  125.    *
  126.    *   Set exposure block to YES to insure the window
  127.    *   is ready for drawing when TdpDraw is called.
  128.    */
  129.   if (argc > 1)
  130.     device_name = argv[1];
  131.   screen = TscOpenSet (device_name, DVCOLORTABLE,
  132.                        V_X_EXPOSURE_BLOCK, YES,
  133.                        V_ACTIVE_CURSOR, V_END_OF_LIST);
  134.   if (!screen)
  135.     {
  136.       printf ("Must specify device on command line or");
  137.       printf (" in DataViews configuration file.\n");
  138.       S_EXIT (EXIT_ERR);
  139.     }
  140.   TscErase (screen);
  141.  
  142.   /*
  143.    *   VOscWinEventMask:  sets the screen's window event mask
  144.    */
  145.   VOscWinEventMask ((ULONG) V_KEYPRESS | V_BUTTONPRESS |
  146.                 V_EXPOSE | V_RESIZE | V_MOTIONNOTIFY,
  147.             (ULONG) 0);
  148.  
  149.   /*
  150.    *   TviLoad:       Load a view from a file, the layout file
  151.    *   TviGetDrawing: Gets drawing object
  152.    *                which TviLoad created as part of the view structure
  153.    */
  154.   layout_view = TviLoad (layout_name);
  155.   if (!layout_view)
  156.     {
  157.       printf ("Could not load view from file ");
  158.       printf ("%s.\n", layout_name);
  159.       S_EXIT (EXIT_ERR);
  160.     }
  161.   layout_dr = TviGetDrawing (layout_view);
  162.  
  163.   /* Create and display drawports */
  164.   for (i = 0; i < NUM_DRAWPORTS; i++)
  165.     {
  166.       /*
  167.        *   TviLoad:     Load a view in from a file, a view file
  168.        */
  169.       view[i] = TviLoad (view_name[i]);
  170.       if (!view[i])
  171.         {
  172.           printf ("Could not load view from file ");
  173.           printf ("%s.\n", view_name[i]);
  174.           S_EXIT (EXIT_ERR);
  175.         }
  176.  
  177.       /*
  178.        *   TdrGetNamedObject: Get a named object from a drawing
  179.        *   VOobBox:           Get an object's bounding box
  180.        *                    gets the rectangular area where the drawport 
  181.        *                    will be shown (may ignore svp_delta in this case)
  182.        */
  183.       VOobBox (TdrGetNamedObject (layout_dr, area_name[i]), &box, &svp_delta);
  184.  
  185.       /* Since the "world coordinates" are -16K to 16K and the
  186.        * "virtual screen coordinates" are    0K to 32K
  187.        * simply add +/- 16K to box (world) to obtain vvp (virtual)
  188.        */
  189.       vvp.ll.x = box.ll.x + XMAX;
  190.       vvp.ll.y = box.ll.y + YMAX;
  191.       vvp.ur.x = box.ur.x + XMAX;
  192.       vvp.ur.y = box.ur.y + YMAX;
  193.  
  194.       /*
  195.        *   Create the drawport
  196.        *   TdpCreateStretch: Create a DV-tools window, a drawport
  197.        *                "drawport" is attached to the screen object, "screen"
  198.        *                "view[i]" is the view to be displayed on the screen
  199.        *                "vvp" specifies the screen viewport, here the
  200.        *                      rectangular area named area_name[i]
  201.        *                "whole_world" specifies the portion of the view to be
  202.        *                      displayed, here the whole view
  203.        *                The whole view will be stretched to fit in the drawport
  204.        */
  205.       drawport[i] = TdpCreateStretch (screen, view[i], &vvp, &whole_world);
  206.  
  207.       /*
  208.        *   TviOpenData: Open all data source lists for this view and views
  209.        *                referenced by enabled subdrawings contained in view
  210.        *   TviReadData: Reads data from the data sources of a view
  211.        *   TdpDraw:     Draw the contents of a drawport
  212.        */
  213.       TviOpenData (view[i]);
  214.       TviReadData (view[i]);
  215.       TdpDraw (drawport[i]);
  216.     }
  217.  
  218.  
  219.   /*--------------------
  220.    *  Control Loop
  221.    *
  222.    *   Poll the event queue for window events specified by the
  223.    *   window mask.  Handle each of the events as they happen.
  224.    *   Events occurring within input objects will be handled
  225.    *   through the event request handler VUerHandleLocEvent.
  226.    *   Draw successive updates of the view after reading a data
  227.    *   iteration. Stop when the user selects "q|Q", the
  228.    *   right mouse button, or selects an object named "quit".
  229.    */
  230.   FOREVER
  231.   {
  232.     /*
  233.      * VOloWinEventPoll:   Poll for the next window event.
  234.      *                     The polling mode used is V_NO_WAIT.
  235.      *                     Using this mode, VOloWinEventPoll
  236.      *               does not wait until a masked event
  237.      *                     is generated.
  238.      *
  239.      * VUerHandleLocEvent: Service the event. This routine will check
  240.      *                     if the event is used by any input objects
  241.      *               such as the slider in play.v.
  242.      */
  243.     location = VOloWinEventPoll (V_NO_WAIT);
  244.     if (location)
  245.       {
  246.         event_status = VUerHandleLocEvent (location);
  247.  
  248.         /*
  249.          * If the return value of VUerHandleLocEvent is INPUT_UNUSED
  250.          * then check for keypress or buttonpress events which
  251.          * represent one of the exit keys as well as checking if
  252.          * an object was selected which has a name of "quit".
  253.          */
  254.         if (event_status == INPUT_UNUSED)
  255.           {
  256.             /*
  257.              *  VOloType:  returns the type of event.  These types
  258.              *             match event types specified in VOscWinEventMask.
  259.              */
  260.             switch (VOloType (location))
  261.               {
  262.  
  263.               case V_RESIZE:
  264.                 /*
  265.                  *  The window size has been changed.
  266.                  *  TscReset:  Resets all screen drawports after
  267.                  *             window resizing
  268.                  */
  269.                 TscReset (screen);
  270.                 break;
  271.  
  272.               case V_EXPOSE:
  273.                 /*
  274.                  *  VOloRegion:  Returns a rectangle representing the
  275.                  *               exposed region on the screen.
  276.                  *  TscRedraw:   After erasing, redraws all the drawports
  277.                  *               in the screen.
  278.                  *  A portion of the window has been exposed and needs
  279.                  *  to be redrawn.
  280.                  */
  281.                 TscRedraw (screen, VOloRegion (location));
  282.                 break;
  283.  
  284.               case V_KEYPRESS:
  285.                 /*
  286.                  *  Check key selected.
  287.          *
  288.                  *  VOloKeySym:                Returns the key symbol value of
  289.          *                   the location object
  290.                  *  TloGetSelectedObjectName:  Get the name of the selected
  291.          *                   object
  292.                  *
  293.                  *  If the key symbol represents the characters 'q'
  294.                  *  or 'Q' then quit the program.
  295.                  *  Any ascii key acts as a possible selection key. A
  296.                  *  selected object with the name "quit" exits the program.
  297.                  */
  298.                 switch (VOloKeySym (location))
  299.                   {
  300.                   case 'q':
  301.                   case 'Q':
  302.                     Quit = YES;
  303.                     break;
  304.  
  305.                   default:
  306.                     if ((obj_name = TloGetSelectedObjectName (location)) &&
  307.                         (strcmp (obj_name, "quit") == 0))
  308.                       Quit = YES;
  309.                     break;
  310.                   }
  311.                 break;
  312.  
  313.               case V_BUTTONPRESS:
  314.                 /*
  315.          *  Check button selected.
  316.          *
  317.          *  VOloButton:                Returns button that was pressed
  318.          *  TloGetSelectedObjectName:  Get name of the selected object
  319.          *
  320.          *  The left mouse button acts as the selection button. A
  321.          *  selected object with the name "quit" signifies the exit
  322.          *  of the program. The right mouse button exits the program.
  323.          */
  324.                 switch (VOloButton (location))
  325.                   {
  326.                   case 1:
  327.                     if ((obj_name = TloGetSelectedObjectName (location)) &&
  328.                         (strcmp (obj_name, "quit") == 0))
  329.                       Quit = YES;
  330.                     break;
  331.  
  332.                   case 3:
  333.                     Quit = YES;
  334.                     break;
  335.  
  336.                   default:
  337.                     break;
  338.                   }
  339.                 break;
  340.  
  341.               case V_MOTIONNOTIFY:
  342.               default:
  343.                 break;
  344.               }
  345.           }
  346.       }
  347.  
  348.     /* exit the program */
  349.     if (Quit == YES)
  350.       break;
  351.  
  352.     /*
  353.      *  TviReadData: Read data from the data sources of the view.
  354.      *  TdpDrawNext: Update all dynamic objects within a drawport's view
  355.      */
  356.     for (i = 0; i < NUM_DRAWPORTS; i++)
  357.       {
  358.         TviReadData (view[i]);
  359.         TdpDrawNext (drawport[i]);
  360.       }
  361.   }
  362.  
  363.  
  364.   /*--------------------
  365.    *   Termination
  366.    *
  367.    *   TscErase:          Erase the entire screen in the default
  368.    *                  background color
  369.    *   TdpDestroy:            Destroy the drawport,
  370.    *   TviCloseData:          Close the data sources of the view
  371.    *   TviDestroy:            Destroy the view, freeing the allocated memory
  372.    *   TscCloseCurrentScreen: Close the current display screen
  373.    *   TTerminate:            Perform the clean-up for DV-Tools
  374.    */
  375.   TscErase (screen);
  376.   for (i = 0; i < NUM_DRAWPORTS; i++)
  377.     {
  378.       TdpDestroy (drawport[i]);
  379.       TviCloseData (view[i]);
  380.       TviDestroy (view[i]);
  381.     }
  382.   TscCloseCurrentScreen ();
  383.   TTerminate ();
  384.   return EXIT_OK;
  385. }
  386.